package org.example;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class ResponseController {
    /*
    * 方式一：HttpServletResponse 设置响应数据
    *
    * */
    @RequestMapping("/response")
    public void resonse(HttpServletResponse response) throws IOException {
        //1.响应状态码
        response.setStatus(HttpServletResponse.SC_OK);
        //2.响应头
        response.setHeader("name","zut");
        //3.响应体
        response.getWriter().write("<h1>hello response<h1>");
    }

    @RequestMapping("/responseEntity")
    public ResponseEntity<String> responseEntity(){
        //设置响应格式
        return ResponseEntity
                .status(HttpServletResponse.SC_OK)
                .header("name","zut")
                .body("<h1>hello responseEntity<h1>");
    }
}
